
package sinhalatransliterartor;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.JFrame;

/**
 * This class provides methods to display a Image.
 * It requires the path to the image which should be displayed.
 */

public class ShowMap extends Panel {
    //To keep the image
    private BufferedImage image;

    /**
     * Read the image file  from the given path
     * @param path  The path to the image
     */
    public ShowMap(String path) {
        try {
            File input = new File(path);
            image = ImageIO.read(input);
        } catch (IOException ie) {
            System.out.println("Error:" + ie.getMessage());
        }
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(getImage(), 0, 0, null);
    }

    /**
     * This method is used to display the Image. The image has been loaded through
     * the constructor.
     * This method displays the image in a frame
     * @param path The path to the image
     */
    public void showKeyMap(String path) {
        JFrame frame = new JFrame("Display image");
        Panel panel = new ShowMap(path);
        frame.getContentPane().add(panel);
        frame.setSize(1300, 580);
        frame.setBackground(new Color(234, 234, 234));
        frame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setAlwaysOnTop(true);
        frame.setVisible(true);
    }

    /**
     * @return the image
     */
    public BufferedImage getImage() {
        return image;
    }

    /**
     * @param image the image to set
     */
    public void setImage(BufferedImage image) {
        this.image = image;
    }
}
